<template>
<q-layout view="hHh Lpr fFf">
    <!-- Be sure to play with the Layout demo on docs -->

    <!-- (Optional) The Header -->
    <q-header elevated>
        <q-toolbar class="body-dark back-dark shadow-7">
            <q-img src="~assets/icons/一方映画logo200708竖版亮色.png" :width="$q.platform.is.mobile ? '150px' : '200px'" contain @click="handleBack" />
            <q-space></q-space>
            <div class="row flex-center q-gutter-xs">
                <q-badge v-if="status==1" outline class="q-pa-sm" color="cyan-6">待审核</q-badge>
                <q-badge v-if="status==2" outline class="q-pa-sm" color="yellow-6">审核中</q-badge>
                <q-badge v-if="status==3" outline class="q-pa-sm" color="green-6">审核完成</q-badge>
                <q-btn flat size="14px" dense icon="share" @click="handleShare" />
                <!-- <q-btn flat size="14px" dense icon="mdi-download"  @click="handleDownload" >

                </q-btn> -->

                <q-separator vertical color="grey-7 q-mx-sm"></q-separator>
                <q-avatar size="30px" v-if="isLogin">
                    <img :src="user.avatar" />
                    <q-menu content-class="bg-grey-9 text-white" anchor="bottom right" self="top right" :offset="[0,10]">
                        <q-card flat class="transparent no-border q-py-none">
                            <q-card-section class="row items-center q-py-sm">
                                <q-avatar size="25px" class="q-mr-sm" v-if="user.avatar">
                                    <img :src="user.avatar" />
                                </q-avatar>
                                {{user.username}}<span :class="user.isQw?'text-orange-4':'text-green-6'">@{{user.isQw?'一方映画':'微信'}}</span>
                            </q-card-section>

                        </q-card>
                        <q-item dense clickable>
                            <q-item-section @click="handleToUserCenter">个人中心</q-item-section>
                        </q-item>
                        <q-separator inset color="grey-4"></q-separator>
                        <q-item dense clickable @click="handleLogout">
                            <q-item-section>退出登录</q-item-section>
                        </q-item>
                    </q-menu>
                </q-avatar>
                <q-btn v-else flat label="登录" @click="handleToLogin">
                </q-btn>

            </div>
        </q-toolbar>
    </q-header>

    <!-- <q-footer>
      <q-tabs switch-indicator>
        <q-route-tab
          icon="map"
          to="/your/route"
          replace
          label="One Tab"
        />
        <q-route-tab
          icon="assignment"
          to="/some/other/route"
          replace
          label="Other Tab"
        />
      </q-tabs>

      <q-toolbar>
        <q-btn
          flat
          round
          dense
          icon="menu"
          @click="leftDrawer = !leftDrawer"
        />
        <q-toolbar-title>
          Footer
        </q-toolbar-title>
      </q-toolbar>
    </q-footer>

    <q-drawer
      v-model="leftDrawer"
      side="left"
      bordered
      content-class="bg-grey-2"
    >

      <q-scroll-area class="fit q-pa-sm">

      </q-scroll-area>
    </q-drawer> -->

    <q-page-container>
        <!-- This is where pages get injected -->
        <router-view ref="review" @update="getFiledata" :status.sync="status"/>
    </q-page-container>

</q-layout>
</template>

<script>
import {
    getfiledata,
} from "assets/api/studio";
import {
    date
} from "quasar";
import {
    getSeconds
} from "assets/utils/stodate";
export default {
    name: 'ReviewLayout',

    data() {
        return {
            user: {
                right: 0,
                isQw: false,
                avatar: '',
            },
            work_id: '',
            pid: '',
            isWechat: false,

            videoData: {},
            loginsrc: '',
            qwloginsrc: '',
            isLogin: false,
            status:1

        }
    },
    created() {
        this.work_id = this.$route.params.work_id;
        this.loadUserInfo();

        if (window.__wxjs_environment === 'miniprogram') {
            this.isWechat = true

        }
        let userinfo = this.$storage.getItem("userinfo");

        if (userinfo) {

            this.isLogin = true;
            this.user = userinfo;
        }

    },
    mounted() {
        if (this.isLogin) {
            this.handleUserRight();
        }

    },
    methods: {
      handleShare(){
        let url = this.GLOBAL.appurl + "/file/" + this.videoData.work_id;
            let msg=`一方映画请您审阅《${this.videoData.name}》\n链接：${url}`
            this.$copyText(msg)
                        .then(() => {
                            this.$message.success('复制链接成功！')
                        })
                        .catch(() => {
                            this.$message.error('复制链接失败！')
                        })
      },
        loadUserInfo() {
            this.user = this.$storage.getItem('userinfo');

        },
        handleBack() {
            this.$router.push('/works/' + this.$refs.review.videoData.pid)
        },
        getFiledata(data) {

            let videoData = data;
            this.videoData=videoData;
            let posterurl = this.GLOBAL.serveurl + videoData.poster;
            if (this.isWechat) {
                wx.miniProgram.postMessage({
                    data: {
                        title: videoData.name,
                        photo: posterurl
                    }
                })
            }

        },
        handleRename(){

        },
        handleDownload(){

        },

        handleLogout() {
            this.$storage.removeItem("userinfo");
            this.$storage.removeItem("user");
            this.isLogin = false;
            this.user = {};
            this.isreply = this.isreplyreply = false;
        },
        handleToLogin() {
            this.$router.push({
                path: '/login',
                query: {
                    redirect: this.$route.fullPath
                }
            })

        },
        handleToUserCenter() {
            this.$router.push('/user')
        },
        //设置用户权利
        handleUserRight() {
            let user = this.user;
            //permission 用户项目权限（1-仅查看；2-可上传；3-可编辑；4-管理员；5-创建者）

            if (user.openid != undefined && user.openid.length > 0) {
                //微信用户

                // this.user.right=item.permission;
                this.user.isQw = false;

            }
            if (user.eid != undefined && user.eid > 0) {
                //企微用户

                // this.user.right=item.permission;
                this.user.isQw = true;

            }

        },
    }
}
</script>
